/******************************************************
 * @file utf-16le.c
 * @author Destiny 
 * @brief utf-16le解码程序
 * 
 * @version 0.1
 * @date 2024-07-18
 *****************************************************/
#include <config.h>
#include <encoding_manager.h>
#include <string.h>

static int isUtf16leCoding(uint8_t *pucBufHead);
static int Utf16leGetCodeFrmBuf(uint8_t *pucBufStart, uint8_t *pucBufEnd, uint32_t *pdwCode);

static T_EncodingOpr g_tUtf16leEncodingOpr = {
	.name          = "utf-16le",
	.iHeadLen	   = 2,
	.isSupport     = isUtf16leCoding,
	.GetCodeFrmBuf = Utf16leGetCodeFrmBuf,
};


static int isUtf16leCoding(uint8_t *pucBufHead)
{
	const char aStrUtf16le[] = {0xFF, 0xFE, 0};
	if (strncmp((const char *)pucBufHead, aStrUtf16le, 2) == 0)
	{
		
		return 1;
	}
	else
	{
		return 0;
	}
}


static int Utf16leGetCodeFrmBuf(uint8_t *pucBufStart, uint8_t *pucBufEnd, uint32_t *pdwCode)
{
	if (pucBufStart + 1 < pucBufEnd)
	{
		*pdwCode = (((uint32_t)pucBufStart[1])<<8) + pucBufStart[0];
		return 2;
	}
	else
	{
		
		return 0;
	}
}


int  Utf16leEncodingInit(void)
{
	AddFontOprForEncoding(&g_tUtf16leEncodingOpr, GetFontOpr("freetype"));
	AddFontOprForEncoding(&g_tUtf16leEncodingOpr, GetFontOpr("ascii"));
	return RegisterEncodingOpr(&g_tUtf16leEncodingOpr);
}


